import Vue from 'vue'
import VueRouter from 'vue-router'
import search from  './search'  //子路由  拆分方便管理
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Main',
    component: () => import('../views/Main.vue')
  },
  {
    path: '/albums',
    name: 'Albums',
    component: () => import('../views/Albums.vue'),
  },
  {
    path: '/song',
    name: 'Song',
    component: () => import('../views/Song.vue'),
    props: (route) => ({id: route.query.subCateId || '',categoryName: route.query.categoryName || ''})
  },
  {
    path: '/song/:id',
    name: 'SongInfo',
    component: () => import('../views/SongInfo.vue'),
  },
  {
    path: '/singer',
    name: 'Singer',
    component: () => import('../views/Singer.vue'),
  },
  {
    path: '/singer/:id',
    name: 'SingerInfo',
    component: () => import('../views/SingerInfo.vue'),
  },
  {
    path: '/vip',
    name: 'VIP',
    component: () => import('../views/VIP.vue')
  },
  ...search
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
